

#ifndef PF_FILEIO_H
#define PF_FILEIO_H

#include <QList>
#include "pf_filterinterface.h"
#include "lx_Export.h"

#define PF_FILEIO PF_FileIO::instance()

//RLZ: TODO destructor for clear filterList
/**
 * API Class for importing files. 
 *

 */
class LX_EXPORT PF_FileIO {
protected:
    PF_FileIO() {}
	
public:
    /**
     * @return Instance to the unique import object.
     */
    static PF_FileIO* instance() {
        if (uniqueInstance==NULL) {
            uniqueInstance = new PF_FileIO();
        }
        return uniqueInstance;
    }
	
    /**
     * Registers a new import filter.
     */
	void registerFilter(PF_FilterInterface* f) {
		filterList.append(f);
	}

    /**
     * @return List of registered filters.
     */
        QList<PF_FilterInterface*> getFilterList() {
		return filterList;
	}

	/**
	 * @return Filter which can import the given file type.
	 */
	PF_FilterInterface* getImportFilter(LX_Define::FormatType t) {
                for (int i = 0; i < filterList.size(); ++i) {
                    if (filterList.at(i)->canImport(t)) {
                                return filterList.at(i);
                        }
                }

		return NULL;
	}
	
	/**
	 * @return Filter which can export the given file type.
	 */
	PF_FilterInterface* getExportFilter(LX_Define::FormatType t) {
                for (int i = 0; i < filterList.size(); ++i) {
                    if (filterList.at(i)->canExport(t)) {
                                return filterList.at(i);
                        }
                }

		return NULL;
	}

    bool fileImport(PF_Graphic& graphic, const QString& file,
		LX_Define::FormatType type = LX_Define::FormatUnknown);
		
    bool fileExport(PF_Graphic& graphic, const QString& file,
		LX_Define::FormatType type = LX_Define::FormatUnknown);

        LX_Define::FormatType detectFormat(const QString& file);

protected:
    static PF_FileIO* uniqueInstance;
    QList<PF_FilterInterface*> filterList;
}
;

#endif
